#include <sys/types.h> 
#include <sys/stat.h> 
#include <string.h> 
#include <stdio.h> 
#include <stdlib.h>
#include <fcntl.h> 
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <assert.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <linux/types.h>
#include "cetc14-iic.h"


int higher2lower(char c);
int htoi(char s[]);




int main(int argc, char *argv[]) 
{
	unsigned int tempval,tempval1;
	int i,count;
	
	unsigned int port, level, group;

	unsigned int reg_address;
	unsigned int value;
	unsigned int sdi_index;

	count = 0;
	tempval = 0;
	tempval1 = 0;
	port = htoi(argv[1]);
	sdi_index=htoi(argv[2]);
	i = 0;

	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Rx_in_p0_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Rx_in_p1_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Rx_in_p2_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Rx_in_p3_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Rx_buf_sop_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Rx_buf_eop_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Rx_out_mf_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Rx_in_mf_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Tx_in_p0_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Tx_in_p1_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Tx_in_p2_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Tx_in_p3_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Tx_drop_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Tx_err_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Buf_in_pkt_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Buf_out_pkt_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Rx_err_cnt:0x%x\n",reg_address,value);
	reg_address = 0x310078 + 0x20000 * port + 0x4 * i++;
	iic_access(sdi_index ,0x58,reg_address,&value,1);
	printf("ADDR 0x%x,Rx_drop_cnt:0x%x\n",reg_address,value);

	return 0;

}

																	
int higher2lower(char c)
{
	if(c >= 'A' && c <= 'Z')
		return c + 'a' - 'A';
	else
	  return c;
}

int htoi(char s[])
{
	int i;
	int n = 0;
	if(s[0] == '0' && (s[1] == 'x' || s[1] == 'x'))
	  i = 2;
	else
	  i = 0;
	for(;(s[i] >= '0' && s[i] <= '9') || (s[i] >= 'a' && s[i] <= 'f') \
			|| (s[i] >= 'A' && s[i] <= 'F'); ++i)
	{
		if(higher2lower(s[i] > '9'))
		{
			n = 16 * n +(10 + higher2lower(s[i]) - 'a');
		}
		else
		  n = 16 * n + (higher2lower(s[i] - '0'));
	}
	return n;
}
